package ua.edu.nuos.jeetraining2012.cms.entity;

import javax.persistence.*;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * Material quiz.
 * <p/>
 * Quiz that user can complete for himself. They can be payed with scores.
 *
 * @author Victor N. Ganichev victor.ganichev@gmail.com
 * @version 1.0 Date: 19.05.13 Time: 15:38
 * @since 1.0
 */
@Entity
@Table(name = "quizes")
public class QuizEntity implements Serializable {

    /**
     * Id.
     */
    @Id
    @SequenceGenerator(
            name = "quizes_id_seq",
            sequenceName = "quizes_id_seq",
            allocationSize = 1
    )
    @GeneratedValue(
            strategy = GenerationType.SEQUENCE,
            generator = "quizes_id_seq"
    )
    @Column(
            name = "id",
            nullable = false,
            insertable = true,
            updatable = false,
            length = 11,
            precision = 0,
            columnDefinition = "SERIAL"
    )
    @NotNull
    private long id;

    /**
     * Quiz data.
     * An JSON object with quiz data. This object should be parsed.
     */
    @Column(name = "data", nullable = false)
    @Basic(optional = false)
    private String data;

    // Default constructor
    public QuizEntity() {}

    // Getters & Setters

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    // Overrides

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        QuizEntity that = (QuizEntity) o;

        if (id != that.id) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return (int) (id ^ (id >>> 32));
    }

}
